﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Swashbuckle.AspNetCore.Annotations;
using System.Threading.Tasks;
using VisionCloud.Api.Common;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Sys;
using VisionCloud.Domain.DtoModel.Sys.UpdateManager;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Sys;

namespace VisionCloud.Api.Controllers.Sys
{
    /// <summary>
    /// 升级管理控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "升级管理控制器")]
    [SystemModule("升级管理控制器")]
    [AllowAnonymous]
    [ApiVersion("1.0")]
    [Route("api/sys/[controller]/[Action]")]
    public class UpdateManagerController : ApiBaseController
    {
        public UpdateManagerService UpdateManagerService { set; get; }

        /// <summary>
        /// Surface端拉取是否需求更新接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost, SwaggerOperation(Tags = new[] { "Surface端升级" })]
        public async Task<ApiResult> GetUpdateInfo(UpdateRqDto request)
        {
            return await TryCatchAsync(UpdateManagerService.GetUpdateInfo(request));
        }

        /// <summary>
        /// 获取Python环境
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous, HttpPost]
        [SwaggerOperation(Tags = new[] { "Surface端升级" })]
        public async Task<ApiResult> GetPythonModes()
        {
            return await TryCatchAsync(UpdateManagerService.GetPythonModes(null));
        }

        /// <summary>
        /// 获取Python环境
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous, HttpPost]
        [SwaggerOperation(Tags = new[] { "Surface端升级" })]
        [SwaggerResponse(0, "Result", typeof(DeviceUpdateResponseDto))]
        public async Task<ApiResult> GetPythonModesByVersion(DeviceUpdateRequestDto deviceUpdate = null)
        {
            return await TryCatchAsync(UpdateManagerService.GetPythonModes(deviceUpdate?.TargetVersion, deviceUpdate?.IsContainPt));
        }
    }
}